package com.huike.stock_analysis.service;


import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.huike.stock_analysis.dao.SearchPageDao;
import com.huike.stock_analysis.entity.News;
import com.huike.stock_analysis.entity.Rank;

@Service
public class SearchPageService {
	@Autowired
	private SearchPageDao searchPageDao;
	
	
	/**
	 * 
	 * @param stock
	 * @return
	 * 查询股票代码
	 */
	public String getCode(String stock) {
		if (searchPageDao.isExist(stock)) {
			return searchPageDao.queryCode(stock);
		}
		return "noExist";
	}
	/**
	 * 
	 * @return
	 * 涨幅排行
	 */
	public Map<String, String> rank(){
		Map<String, String> map = new LinkedHashMap<>();
		List<Rank> ranks = searchPageDao.stockRank();
		
		for (Rank rank : ranks) {
			map.put(rank.getName(), rank.getChange() + "," + rank.getCode());
		}
		return map;
	}
	public List<Rank> rank1(){
		//Map<String, String> map = new LinkedHashMap<>();
		List<Rank> ranks = searchPageDao.stockRank();
		return ranks;
	}
	
	/**
	 * 
	 * @return
	 * 新闻
	 */
	
	public List<News> news(){
		//Map<String, String> map = new LinkedHashMap<>();
		List<News> newses = searchPageDao.news();
		return newses;
	}
	
}
